class Solution:
    def reverse(self, x: int):
        if -10 < x < 10:
            return x
        str_x = str(x)
        if x > 0:
            str_x = str_x[::-1]
            str_x = int(str_x)
        else:
            str_x = str_x[:0:-1]
            str_x = -int(str_x)
        if str_x < 2 ** 31 - 1 and str_x > -2 ** 31:
            return str_x
        else:
            return 0


if __name__ == '__main__':
    a = Solution()
    print(a.reverse(1))
